package net.oschina.renyong.query.generator.po;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * 一个查询配置
 * @author Timothy
 */
@XmlRootElement(name = "configQuery")
@XmlAccessorType(XmlAccessType.FIELD)
public class ConfigQuery {

	/** 查询的命名，要求唯一；必填 */
	@XmlAttribute
	private String name;
	/** 查询注释；可选 */
	private String comment;
	/** 是否提供查总数的方法；可选，默认false */
	private Boolean sqlCount;
	/** 用于语法分析的SQL语句；必填 */
	private String sqlForParse;
	/** mapper xml中的查询sql，选填；如不填，系统以sqlForParse为基础在后面追加${ew.whereFull}，那就不一定是你想要的 */
	private String sql;
	/** 用于where/group/having/order而不用于select的字段名，多个字段名之间用英文逗号分隔；可选 */
	private String noSelectField;
	/** 替换字段，有些字段直接填写原内容在sql解析时会出错，可以在sqlForParse用替代内容，再利用replaceField来替换回来 */
	private String replaceField;

	public String getName() {
		return name;
	}

	public ConfigQuery setName(String name) {
		this.name = name;
		return this;
	}

	public String getComment() {
		return comment;
	}

	public ConfigQuery setComment(String comment) {
		this.comment = comment;
		return this;
	}

	public Boolean getSqlCount() {
		return sqlCount;
	}

	public void setSqlCount(Boolean sqlCount) {
		this.sqlCount = sqlCount;
	}

	public String getSqlForParse() {
		return sqlForParse;
	}

	public ConfigQuery setSqlForParse(String sqlForParse) {
		this.sqlForParse = sqlForParse;
		return this;
	}

	public String getSql() {
		if (sql == null && sqlForParse != null) {
			return sqlForParse + " ${ew.whereFull}";
		}
		return sql;
	}

	public ConfigQuery setSql(String sql) {
		this.sql = sql;
		return this;
	}

	public String getNoSelectField() {
		return noSelectField;
	}

	public void setNoSelectField(String noSelectField) {
		this.noSelectField = noSelectField;
	}

	public String getReplaceField() {
		return replaceField;
	}

	public ConfigQuery setReplaceField(String replaceField) {
		this.replaceField = replaceField;
		return this;
	}
}
